/*
 * FlightController.h
 *
 *  Created on: Sep 5, 2013
 *      Author: gonprieto
 */

#ifndef FLIGHTCONTROLLER_H_
#define FLIGHTCONTROLLER_H_

#include <vector>
#include "FlightState.h"
#include "../utils/Logger.h"
#include "../comunication/inbox/FlightControllerInbox.h"
#include "../comunication/DTO/DTOFlightControler.h"
#include "../comunication/DTO/DTORunwayRelated.h"
#include "../comunication/inbox/FlightInbox.h"
#include "../utils/Semaforo.h"
#include "Proceso.h"

class FlightController : public Proceso {
public:
	FlightController(unsigned int id,int runwayCount);
	virtual ~FlightController();

	int run();
protected:
	void procesarFlightRelated(DTOFlightRelated* dto);
	void procesarRunwayRelated(DTORunwayRelated* dto);
	void procesarFlightController(DTOFlightControler* dto);

	int tomarRunway();

private:
	FlightControllerInbox inbox;
	Semaforo* semRunways;

	std::vector<DTOFlight> flightsManejando;

	int runwaysCount;
	unsigned int id;

	bool isRunning;

	void asignarRunway(unsigned int runwayId);

	void landFlight(unsigned int flightId,FlightInbox* fi,unsigned int runwayId);
	void takeOffFlight(unsigned int flightId,FlightInbox* fi,unsigned int runwayId);


	bool isRunwayBusy(unsigned int runway);

	DTOFlight getVueloPrioritario();
};


#endif /* FLIGHTCONTROLLER_H_ */
